//
//  YTXTime.h
//  Chart
//
//  Created by CaoJun on 15/2/15.
//
//

#ifndef __Chart__YTXTime__
#define __Chart__YTXTime__

#include "YTXObject.h"
#include "YTXChartTools.h"

#include <stdio.h>
#include <time.h>
#include <string>

namespace ytx
{
    static long days(int d){
        return d * 24 * 3600;
    }

    static long hours(int h){
        return h * 3600;
    }

    static long minutes(int m){
        return m * 60;
    }

    static long seconds(int m){
        return m;
    }
    
    class ignore{
    public:
        int value;
        ignore(int y):value(y){
            days(0);
            hours(0);
            minutes(0);
            seconds(0);
        }
    };

    class months{
    public:
        int value;
        months(int m):value(m){
        }
    };

    class years{
    public:
        int value;
        years(int y):value(y){
        }
    };

    class YTXTime;

    typedef YTXTime YTXTimeDuration;
    typedef YTXTime YTXTimeDate;

    class YTXTime : public YTXObject {
    private:
        bool isLeapYear(int year);
        int getDaysInMonth(int year, int month);

    protected:
        tm * toTM();
        tm * toGMT8();
        time_t currentTime;
    public:

        YTXTime();
        YTXTime(std::string time);
        //月份都是1-12
        YTXTime(time_t currentTime);
        //要大于1900
        YTXTime(int	tm_year,
                         int	tm_mon,
                         int	tm_mday,
                         int	tm_hour,
                         int 	tm_min,
                         int	tm_sec);

        YTXTime(const YTXTime &);

        static YTXTime initByGMT8();
        static YTXTime initByGMT8(std::string time);
        //要大于1900
        static YTXTime initByGMT8(int	tm_year,
                                  int	tm_mon,
                                  int	tm_mday,
                                  int	tm_hour,
                                  int 	tm_min,
                                  int	tm_sec);

        static YTXTime initByDateAndTimeOfDay(YTXTimeDate date, YTXTimeDuration time_of_day);

        static YTXTime initByGMT8DateAndGMT8TimeOfDay(YTXTimeDate date, YTXTimeDuration time_of_day);

        static YTXTime initByDateAndTimeOfDay(YTXTimeDate date, int	tm_hour, int tm_min, int tm_sec);

        static YTXTime initByGMT8DateAndGMT8TimeOfDay(YTXTimeDate date, int	tm_hour, int tm_min, int tm_sec);

        static YTXTime not_a_date_time();

        static YTXTime max_date_time();

        static YTXTime min_date_time();

        YTXTime time_of_day();

        YTXTime date();

        time_t getCurrentTime() const
        {
            return currentTime;
        }

        time_t getCurrentTimeToMillisecond() const
        {
            return currentTime * 1000;
        }

        bool is_not_a_date_time();

        int day_of_week();
        int day_of_year();

        int day_of_week_gmt8();
        int day_of_year_gmt8();

        YTXTime start_of_week_since_monday();

        YTXTime start_of_month();
        
        YTXTime end_of_month();

        int getYear();
        int getMonth();
        int getDay();
        int getHour();
        int getMinute();
        int getSecond();
        
        //修复getDay不准确的问题
        int getDiffDay();

        bool isLeapYear();
        int getDaysInMonth();

        long toSeconds();
        
        YTXTime GMT8();

        std::string toStringify(std::string format, int size);

        std::string toGTM8Stringify(std::string format, int size);

        std::string toStringHHmm();

        std::string toStringMMddHHmmss();
        
        std::string toStringMM_ddHHmmss();

        std::string toStringMMddHHmm();
        
        std::string toStringMM_ddHHmm();

        std::string toStringYYYYMMdd();
        std::string toStringYYYY_MM_dd();
        std::string toStringMMdd();
        
        std::string toStringddHHmm();

        std::string toStringYYYYMMddHHmmss();

        std::string toStringGMT8HHmm();

        std::string toStringGMT8MMddHHmmss();

        std::string toStringGMT8MMddHHmm();

        std::string toStringGMT8YYYYMMdd();

        std::string toStringGMT8YYYYMMddHHmmss();

        YTXTime operator+(long seconds);

        YTXTime operator-(long seconds);

        YTXTime operator+(months m);

        YTXTime operator-(months m);

        YTXTime operator+(years y);

        YTXTime operator-(years y);

        long operator+(YTXTime time);

        long operator-(YTXTime time);

        YTXTime operator+=(long seconds);

        YTXTime operator-=(long seconds);

        YTXTime operator+=(months m);

        YTXTime operator-=(months m);

        YTXTime operator+=(years y);

        YTXTime operator-=(years y);

        bool operator>(YTXTime time);

        bool operator<(YTXTime time);

        bool operator>=(YTXTime time);

        bool operator<=(YTXTime time);

        bool operator==(YTXTime time);
        
        bool operator!=(YTXTime time);

    };

}

#endif /* defined(__Chart__YTXTime__) */
